package com.kethink.clsssify.jvm;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

class Demo {
    public int field1;
    private String field2 = "a";
    public void method1(Integer arg0) {
        System.out.println("执行method1");
    }
    private String method1() { return null;}
}

public class ChangeMethod {
    public static void main(String[] args) throws Exception {
        Class<Demo> demoClass = Demo.class;
        Demo demo = demoClass.newInstance();
        Field field2 = demoClass.getDeclaredField("field2");
        field2.setAccessible(true);
        field2.set(demo, "setField2");
        System.out.println(field2.get(demo));
        Method method1 = demoClass.getMethod("method1", Integer.class);
        method1.invoke(demo, new Object[]{11});
    }
    /**
     * setField2
     * 执行method1
     */
}
